package com.ruoyi.system.api.wrapper;

import com.ruoyi.common.core.constant.SecurityConstants;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.system.api.RemoteSysConfigService;
import com.ruoyi.system.api.domain.SysConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 参数配置微服务包装服务，对微服务接口进行了封装，直接返回需要的数据。
 *
 * @author ruoyi
 * @date 2023-04-26
 */
@Component
public class RemoteSysConfigWrapperService extends RemoteBaseWrapperService {

    @Autowired
    private RemoteSysConfigService remoteSysConfigService;

    /**
     * 查询参数配置
     *
     * @param configId 参数配置主键
     * @return 参数配置
     */
    public SysConfig selectSysConfigByConfigId(Long configId) {
        R<SysConfig> result = remoteSysConfigService.selectSysConfigByConfigId(configId, SecurityConstants.INNER);
        return processResult(result);
    }

    /**
     * 查询参数配置列表
     *
     * @param sysConfig 参数配置
     * @return 参数配置集合
     */
    public List<SysConfig> selectSysConfigList(SysConfig sysConfig) {
        R<List<SysConfig>> result = remoteSysConfigService.selectSysConfigList(sysConfig, SecurityConstants.INNER);
        return processResult(result);
    }

    /**
     * 新增参数配置
     *
     * @param sysConfig 参数配置
     * @return 结果
     */
    public Integer insertSysConfig(SysConfig sysConfig) {
        R<Integer> result = remoteSysConfigService.insertSysConfig(sysConfig, SecurityConstants.INNER);
        return processResult(result);
    }

    /**
     * 修改参数配置
     *
     * @param sysConfig 参数配置
     * @return 结果
     */
    public Integer updateSysConfig(SysConfig sysConfig) {
        R<Integer> result = remoteSysConfigService.updateSysConfig(sysConfig, SecurityConstants.INNER);
        return processResult(result);
    }

    /**
     * 批量删除参数配置
     *
     * @param configIds 需要删除的参数配置主键集合
     * @return 结果
     */
    public Integer deleteSysConfigByConfigIds(Integer[] configIds) {
        R<Integer> result = remoteSysConfigService.deleteSysConfigByConfigIds(configIds, SecurityConstants.INNER);
        return processResult(result);
    }

    public Integer resetConfigCache() {
        R<Integer> result = remoteSysConfigService.resetConfigCache(SecurityConstants.INNER);
        return processResult(result);
    }

    public String selectConfigByKey(String key) {
        R<String> result = remoteSysConfigService.selectConfigByKey(key, SecurityConstants.INNER);
        return processResult(result);
    }
}
